package net.zjitc.search;

/**
 * Created by Administrator on 2017/6/1.
 */
public class Search {
    //使用顺序查询
    public int squSearch(int []data,int key){
        int n=data.length;
        for (int i=0;i<n;i++){
            if (key==data[i]){
                return i;
            }
        }
        return -1;
    }
    //二分查询
    public int binSearch(int[]data,int key){
        int low=0;//初始值
        int high=data.length;
        int mid;
/*
        }*/
        while(high>=low){
            mid=(low+high)/2;
            if (key==data[mid]){
                return mid;
            }else  if(key>data[mid])
                low=mid+1;
            else high=mid-1;
        }
        return -1;
    }
}
